package com.xuxiang.cloud.controller;

import com.xuxiang.cloud.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;

/**
 * @author xuxiang 2019/5/29 11:42
 */
@RestController
public class HelloController {

    @Autowired
    private HelloService helloService;

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("hello")
    public String hello(String name) {
        return helloService.hello(name);
    }

    @RequestMapping("testHello")
    public String testHello(String name) {
        return restTemplate.getForObject("http://spring-server-consul/hello?name={name}", String.class, new HashMap<String, String>() {
            {
                put("name", name);
            }
        });
    }

}
